package org.kabeja.parser.entities;

import org.kabeja.dxf.entity.DXFEntity;
import org.kabeja.dxf.entity.DXFLWPolyline;
import org.kabeja.dxf.entity.DXFVertex;
import org.kabeja.parser.DXFValue;

/**
 * @author shutao
 * @since 2022/4/25 11:34
 */
public class DXFLWPolylineHandler extends AbstractEntityHandler {
    public static final String ENTITY_NAME = "LWPOLYLINE";
    public static final int VERTEX_BULGE = 42;
    public static final int START_WIDTH = 40;
    public static final int END_WIDTH = 41;
    public static final int CONSTANT_WIDTH = 43;
    public static final int ELEVATION = 38;
    public static final int THICKNESS = 39;
    private DXFVertex vertex;
    private DXFLWPolyline lwpolyline;

    public DXFLWPolylineHandler() {
    }

    @Override
    public void endDXFEntity() {
    }

    @Override
    public DXFEntity getDXFEntity() {
        return this.lwpolyline;
    }

    @Override
    public String getDXFEntityName() {
        return "LWPOLYLINE";
    }

    @Override
    public boolean isFollowSequence() {
        return false;
    }

    @Override
    public void parseGroup(int var1, DXFValue var2) {
        switch(var1) {
            case 10:
                this.createVertex();
                this.vertex.setX(var2.getDoubleValue());
                break;
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
            case 19:
            case 21:
            case 22:
            case 23:
            case 24:
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 31:
            case 32:
            case 33:
            case 34:
            case 35:
            case 36:
            case 37:
            default:
                super.parseCommonProperty(var1, var2, this.lwpolyline);
                break;
            case 20:
                this.vertex.setY(var2.getDoubleValue());
                break;
            case 30:
                this.vertex.setZ(var2.getDoubleValue());
                break;
            case 38:
                this.lwpolyline.setElevation(var2.getDoubleValue());
                break;
            case 39:
                this.lwpolyline.setThickness(var2.getDoubleValue());
                break;
            case 40:
                this.vertex.setStartWidth(var2.getDoubleValue());
                break;
            case 41:
                this.vertex.setEndWidth(var2.getDoubleValue());
                break;
            case 42:
                this.vertex.setBulge(var2.getDoubleValue());
                break;
            case 43:
                this.lwpolyline.setConstantWidth(var2.getDoubleValue());
        }

    }

    @Override
    public void parseObject(int var1, DXFValue var2, int type) {
        super.parseObjectProperty(var1, var2, type, this.vertex);
        super.parseObjectProperty(var1, var2, type, this.lwpolyline);
    }

    @Override
    public void startDXFEntity() {
        this.lwpolyline = new DXFLWPolyline();
    }

    private void createVertex() {
        this.vertex = new DXFVertex();
        this.vertex.setDXFDocument(this.doc);
        this.lwpolyline.addVertex(this.vertex);
    }
}
